<script setup>
  import { ref } from 'vue'
  import { onLoad } from '@dcloudio/uni-app'
  import taskApi from '@/apis/task.js'
  // 提货凭证图片
  const receiptPictrues = ref([])
  // 货品图片
  const goodsPictrues = ref([])
  const id = ref(0) //作业id

  onLoad((params) => {
    id.value = params.id
  })

  async function onSubmit() {
    // 1. 构建了接口要求的请求体数据
    const formData = {
      id: id.value,
      cargoPickUpPictureList: receiptPictrues.value.map((obj) => {
        return { url: obj.url }
      }),
      cargoPictureList: goodsPictrues.value.map((obj) => {
        return { url: obj.url }
      }),
    }
    // 2. 调用服务器接口，实现提货操作
    let { msg } = await taskApi.pickup(formData)
    // 3. 提示用户并跳转到任务列表页面
    uni.utils.toast(msg)
    uni.switchTab({
      url: '/pages/task/index',
    })
  }
</script>
<template>
  <view class="page-container">
    <view class="receipt-info">
      <uni-file-picker
        v-model="receiptPictrues"
        limit="3"
        file-extname="jpg,webp,gif,png"
        title="请拍照上传回单凭证"
      ></uni-file-picker>
      <uni-file-picker
        v-model="goodsPictrues"
        limit="3"
        file-extname="jpg,webp,gif,png"
        title="请拍照上传货品照片"
      ></uni-file-picker>
    </view>
    <button class="button" @click="onSubmit">提交</button>
  </view>
</template>

<style lang="scss" scoped>
  .page-container {
    padding: 30rpx;
  }

  .receipt-info {
    min-height: 600rpx;
    background-color: #fff;
    padding: 20rpx 30rpx;
    border-radius: 16rpx;

    ::v-deep .uni-file-picker {
      margin-bottom: 30rpx;
    }
  }

  .button {
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    /* #ifdef APP */
    padding-top: 4rpx;
    /* #endif */
    border-radius: 100rpx;
    margin-top: 60rpx;
    color: #fff;
    font-size: $uni-font-size-big;
    background-color: $uni-primary;

    &[disabled],
    &.disabled {
      color: #fff;
      background-color: #fadcd9;
    }
  }
</style>
